/**
 * @param {string} digits
 * @return {string[]}
 */
 var letterCombinations = function(digits) {
  let res = [],
    path = []
  len = digits.length
  const letters = [
    '',
    '',
    'abc',
    'def',
    'ghi',
    'jkl',
    'mno',
    'pqrs',
    'tuv',
    'wxyz',
  ]
  if (len == 0) return res
  if(len ==1) return letters[digits].split('')
  else {
    backtracing(digits,len,0)
  }

  function backtracing(letter,n,a){
    console.log(letters[digits[a]]);
    if(path.length==n){
      res.push(path.join(""))
      return
    }
    for( letter of letters[digits[a]]){
      path.push(letter)
      backtracing(digits,n,a+1)
      path.pop()
    }
  }

  return res
};

letterCombinations('23')